package com.aks.server.service.impl;

import com.aks.server.domain.response.ResponseResult;
import com.aks.server.domain.request.param.TaskParam;
import com.aks.server.entity.TaskEntity;
import com.aks.server.mapper.TaskMapper;
import com.aks.server.service.TaskService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

@Service("taskService")
public class TaskServiceImpl extends BaseServiceImpl implements TaskService {
    @Resource
    private TaskMapper taskMapper;

    @Override
    public ResponseResult<?> createTask(TaskParam param) {
        TaskEntity entity = new TaskEntity();
        BeanUtils.copyProperties(param, entity);
        taskMapper.insert(entity);
        return ResponseResult.success(null, entity);
    }

    @Override
    public ResponseResult<?> updateTask(TaskParam param) {
        TaskEntity entity = new TaskEntity();
        BeanUtils.copyProperties(param, entity);
        taskMapper.updateById(entity);
        return ResponseResult.success(null, entity);
    }

    @Override
    public ResponseResult<?> deleteTask(Long id) {
        taskMapper.deleteById(id);
        return ResponseResult.success(null, null);
    }

    @Override
    public ResponseResult<?> getTaskById(Long id) {
        return null;
    }


    @Override
    public List<TaskEntity> listTasks(Long activityId) {
        LambdaQueryWrapper<TaskEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskEntity::getActivityId, activityId);
        List<TaskEntity> list = taskMapper.selectList(wrapper);
        return list;
    }

    @Override
    public List<TaskEntity> getTasksByActivityList(List<Long> activityIds) {
        return taskMapper.getTasksByActivityList(activityIds);
    }
} 